package com.acctrue.common.jwt.filter;

import com.acctrue.common.jwt.utils.JwtTokenUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Slf4j
@Component
public class JwtTokenInterceptor implements RequestInterceptor {
    @Resource
    JwtTokenUtil jwtTokenUtil;
    @Override
    public void apply(RequestTemplate template) {
        // 从上下文或其他地方获取 JWT Token
        String accessToken = MDC.get("accessToken");
        String refreshToken = MDC.get("refreshToken");
        // 将 Token 添加到请求头
        template.header("Authorization", accessToken);
        template.header("RefreshToken", refreshToken);
        MDC.remove("accessToken");
        MDC.remove("refreshToken");
    }
}
